package twoD.hofem.Q;

import inf.jlinalg.Vector2D;

/**
 * Create the Straight Edge Function E(xi)=P1*(0.5*(1-xi))+P2*(0.5*(1+xi)) 
 * where P1 is the start point and P2 the end point.
 * 
 * @author White Horse
 * 
 */

public class StraightEf extends EdgeFunction {

	protected void initialize() {
	}
	
	/**
	 * Evaluates the tangent at the specified point.
	 * 
	 * @param x
	 *            point
	 * @return the tangent (array of length n)
	 */
	public double[] tangentAt(double x) {
		Vector2D p1 = this.getStartPoint();
		Vector2D p2 = this.getEndPoint();
		return (p1.multiply(-0.5).add(p2.multiply(0.5))).toArray();
	}

	/**
	 * Computes the function value at the specified point
	 * 
	 * @param x
	 *            point
	 * @return the function value (array of length n)
	 */
	public double[] valueAt(double x) {
		Vector2D p1 = this.getStartPoint();
		Vector2D p2 = this.getEndPoint();
		return ((p1.multiply(0.5*(1-x))).add(p2.multiply(0.5*(1+x))
				)).toArray();
	}

}
